package net.bithappens.hnqe.graph;

import java.util.Calendar;
import java.util.Date;

import net.bithappens.hnqe.IllegalParamException;

public class EntryValue {

	private Object value;
	
	public EntryValue(Integer value) throws IllegalParamException {
		if(value == null){
			throw new IllegalParamException("the value must not be null");
		}
		this.value = value;
	}
	
	public EntryValue(String value) throws IllegalParamException {
		if(value == null){
			throw new IllegalParamException("the value must not be null");
		}
		this.value = value;
	}
	
	public EntryValue(Boolean value) throws IllegalParamException {
		if(value == null){
			throw new IllegalParamException("the value must not be null");
		}
		this.value = value;
	}

	public EntryValue(Double value) throws IllegalParamException {
		if(value == null){
			throw new IllegalParamException("the value must not be null");
		}
		this.value = value;
	}
	
	public EntryValue(Number value) throws IllegalParamException {
		if(value == null){
			throw new IllegalParamException("the value must not be null");
		}
		this.value = value;
	}
	
	public EntryValue(Float value) throws IllegalParamException {
		if(value == null){
			throw new IllegalParamException("the value must not be null");
		}
		this.value = value;
	}
	
	public EntryValue(Date value) throws IllegalParamException {
		if(value == null){
			throw new IllegalParamException("the value must not be null");
		}
		Calendar cal = Calendar.getInstance();
		cal.setTime(value);
		this.value = cal;
	}
	
	public EntryValue(Calendar value) throws IllegalParamException {
		this.value = value;
	}
	
	
	public Object getValue(){
		return value;
	}

	public String getValueType() {
		if(value instanceof Calendar){
			return "Date";
		}
		return value.getClass().getSimpleName();
	}
	
	
	
	@Override
	public String toString() {
		if(value instanceof Calendar){
			return ((Calendar) value).getTime().toString();
		}
		return value.toString();
	}
	
	public static EntryValue createEntryValue(Object value) throws IllegalParamException{
		
		if(value instanceof String){
			return new EntryValue((String) value);
		}
		
		if(value instanceof Integer){
			return new EntryValue((Integer) value);
		}
		
		if(value instanceof Double){
			return new EntryValue((Double)value);
		}
		
		if(value instanceof Boolean){
			return new EntryValue((Boolean) value);
		}
		
		if(value instanceof Float){
			return new EntryValue((Float) value);
		}
		
		if(value instanceof Number){
			return new EntryValue((Number)value);
		}
		
		if(value instanceof Date){
			return new EntryValue((Date)value);
		} 		
		
		return null;
	}	
}
